package com.ihisomp.controller;

import com.ihisomp.base.Result;
import com.ihisomp.dto.OrgDeptDto;
import com.ihisomp.service.IOrgDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 机构科室前端控制器 前端控制器
 * </p>
 *
 * @author zy
 * @since 2022-03-21
 */
@RestController
@Api(value = "机构科室信息", tags = "机构科室信息")
@RequestMapping("/orgDept")
public class OrgDeptController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private IOrgDeptService orgDeptService;

    /**
     * 机构科室列表
     *
     * @param orgDeptDto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("机构科室列表")
    @ApiImplicitParam(name = "orgDeptDto", value = "机构科室数据类", required = true)
    public Result selectList(@RequestBody(required = false) OrgDeptDto orgDeptDto) {
        logger.info("机构科室列表：orgDeptDto={}", orgDeptDto);
        Result result = orgDeptService.list(orgDeptDto);
        return result;
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @param orgDeptDto
     * @return
     */
    @PostMapping("/search/{page}/{size}")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true),
            @ApiImplicitParam(name = "orgDeptDto", value = "机构科室数据类", required = true)})
    public Result search(@PathVariable("page") long page,
                         @PathVariable("size") long size,
                         @RequestBody(required = false) OrgDeptDto orgDeptDto) {
        logger.info("分页查询：page={}, size={}, orgDeptDto={}", size, size, orgDeptDto);
        Result result = orgDeptService.search(page, size, orgDeptDto);
        return result;
    }

    /**
     * 新增数据
     *
     * @param orgDeptDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增数据")
    @ApiImplicitParam(name = "orgDeptDto", value = "机构科室数据类", required = true)
    public Result add(@RequestBody OrgDeptDto orgDeptDto) {
        logger.info("新增数据：orgDeptDto={}", orgDeptDto);
        Result result = orgDeptService.add(orgDeptDto);
        return result;
    }

    /**
     * 更新数据
     *
     * @param deptKey
     * @param orgDeptDto
     * @return
     */
    @PostMapping("/update/{deptKey}")
    @ApiOperation("更新数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deptKey", value = "机构科室主键", required = true),
            @ApiImplicitParam(name = "orgDeptDto", value = "机构科室数据类", required = true)})
    public Result update(@PathVariable("deptKey") String deptKey, @RequestBody OrgDeptDto orgDeptDto) {
        logger.info("更新数据：deptKey={}, orgDeptDto={}", deptKey, orgDeptDto);
        Result result = orgDeptService.update(deptKey, orgDeptDto);
        return result;
    }

    /**
     * 查询数据
     *
     * @param deptKey
     * @return
     */
    @GetMapping("/get/{deptKey}")
    @ApiOperation("查询数据")
    @ApiImplicitParam(name = "deptKey", value = "机构科室主键", required = true)
    public Result get(@PathVariable("deptKey") String deptKey) {
        logger.info("查询数据：deptKey={}", deptKey);
        Result result = orgDeptService.get(deptKey);
        return result;
    }

    /**
     * 更新状态
     *
     * @param deptKey
     * @param activeFlg
     * @return
     */
    @PostMapping("status/{deptKey}/{activeFlg}")
    @ApiOperation("更新状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deptKey", value = "机构科室主键", required = true),
            @ApiImplicitParam(name = "activeFlg", value = "机构科室状态", required = true)})
    public Result updateStatus(@PathVariable("deptKey") String deptKey,
                               @PathVariable("activeFlg") int activeFlg) {
        logger.info("更新状态：deptKey={}, activeFlg={}", deptKey, activeFlg);
        Result result = orgDeptService.updateStatus(deptKey, activeFlg);
        return result;
    }

}
